#include "stdafx.h"
#include "CommandDef.h"
#include "debug_new.h"
#include "Util/UtilInclude.h"
#include "CMSGLanguageCon.h"
#include "MainMenuPainter.h"
#include "IResCfg.h"
#include "CMSGInforCon.h"

#include "cmyreg.h"
CMSGLanguageCon::CMSGLanguageCon(HWND hWnd):CMSGInforCon(hWnd)
{

}

CMSGLanguageCon::~CMSGLanguageCon(void)
{
}

BOOL CMSGLanguageCon::InitControls(DWORD dwData)
{
	//message box
	LANGUAGE_DECLARE;
	FONT_DECLARE;

	HBITMAP hBitmap = NULL;

	CIResCfg ResCon;
	if(!ResCon.Init(L"MSGLanguage.xml"))
	{
		//g_App.ShowMsgBox(CMD_MSGBOX_OK,L"",LAN_GETTEXT(Msg_ResError));
		return FALSE;
	}

	m_nAniType  = ResCon.GetAniType();
	m_nExitAniType=ResCon.GetExitAniType();
	m_nAniSpeed = ResCon.GetAniSpeed();
	SetRect(ResCon.GetRect());
	BOOL bFromDll = ResCon.IsResFromDll();
	BtnParam btnInfo;

	hBitmap = CUtil::LoadBitmapEx(ResCon.GetImage(),bFromDll);
    	this->SetMaskBmp(hBitmap);

	BatTimePicParam picInfo;
	ResCon.GetBatTimePicParam(picInfo,L"Pic_Bkgnd");
	CPicture *pPic = (CPicture*)AddControl(new CPicture(SWS_STATIC, L"",picInfo.m_rc, CMD_MSGBOX_PIC));
	ResCon.SetPicParam(pPic,picInfo);

	TextParam txtInfo;
	CText* pText=NULL; 

	//if(m_strCaption.size()>0)
	//{
	ResCon.GetTextParam(txtInfo,L"Title");
	pText = (CText*)AddControl(new CText(SWS_STATIC,LAN_GETTEXT(HS_LANG),txtInfo.m_rc, CMD_MSGBOX_TEXT));
	ResCon.SetTextParam(pText,txtInfo);
	//}
	CBmpBtn* pBtn = NULL;
  if (dwData)
  {
	  ResCon.GetBtnParam(btnInfo,L"Btn_No");
	  pBtn = (CBmpBtn*)AddControl(new CBmpBtn(SBS_RECT,LAN_GETTEXT(MSG_CANCLE),btnInfo.m_rc, CMD_MSG_MSGLAN_CANCLE1));
	  ResCon.SetBtnParam(pBtn,btnInfo);

	  ResCon.GetBtnParam(btnInfo,L"Btn_Yes");
	  pBtn = (CBmpBtn*)AddControl(new CBmpBtn(SBS_RECT,LAN_GETTEXT(MSG_OK),btnInfo.m_rc, CMD_MSG_MSGLAN_YES1));
	  ResCon.SetBtnParam(pBtn,btnInfo);
  }
  else
  {
	  ResCon.GetBtnParam(btnInfo,L"Btn_No");
	pBtn = (CBmpBtn*)AddControl(new CBmpBtn(SBS_RECT,LAN_GETTEXT(MSG_CANCLE),btnInfo.m_rc, CMD_MSG_MSGLAN_CANCLE));
	ResCon.SetBtnParam(pBtn,btnInfo);

	ResCon.GetBtnParam(btnInfo,L"Btn_Yes");
	pBtn = (CBmpBtn*)AddControl(new CBmpBtn(SBS_RECT,LAN_GETTEXT(MSG_OK),btnInfo.m_rc, CMD_MSG_MSGLAN_YES));
	ResCon.SetBtnParam(pBtn,btnInfo);

  }

   
    m_strlang=CConfig::GetInstance()->GetLanguage();
	ResCon.GetBatTimePicParam(picInfo,L"LangIcon_English");
	pPic = (CPicture*)AddControl(new CPicture(SWS_STATIC,L"",picInfo.m_rc, CMD_MSGBOX_PIC));
	ResCon.SetPicParam(pPic,picInfo);

	ResCon.GetBatTimePicParam(picInfo,L"LangIcon_German");
	pPic = (CPicture*)AddControl(new CPicture(SWS_STATIC,L"",picInfo.m_rc, CMD_MSGBOX_PIC));
	ResCon.SetPicParam(pPic,picInfo);

	ResCon.GetBatTimePicParam(picInfo,L"LangIcon_French");
	pPic = (CPicture*)AddControl(new CPicture(SWS_STATIC,L"",picInfo.m_rc, CMD_MSGBOX_PIC));
	ResCon.SetPicParam(pPic,picInfo);

	ResCon.GetBatTimePicParam(picInfo,L"LangIcon_Italian");
	pPic = (CPicture*)AddControl(new CPicture(SWS_STATIC,L"",picInfo.m_rc, CMD_MSGBOX_PIC));
	ResCon.SetPicParam(pPic,picInfo);


	ResCon.GetBatTimePicParam(picInfo,L"LangIcon_Spanish");
	pPic = (CPicture*)AddControl(new CPicture(SWS_STATIC,L"",picInfo.m_rc, CMD_MSGBOX_PIC));
	ResCon.SetPicParam(pPic,picInfo);



	ResCon.GetBatTimePicParam(picInfo,L"LangIcon_Nederlands");
	pPic = (CPicture*)AddControl(new CPicture(SWS_STATIC,L"",picInfo.m_rc, CMD_MSGBOX_PIC));
	ResCon.SetPicParam(pPic,picInfo);




	ResCon.GetBatTimePicParam(picInfo,L"LangIcon_Portuguess");
	pPic = (CPicture*)AddControl(new CPicture(SWS_STATIC,L"",picInfo.m_rc, CMD_MSGBOX_PIC));
	ResCon.SetPicParam(pPic,picInfo);




	ResCon.GetBatTimePicParam(picInfo,L"LangIcon_ChineseGB");
	pPic = (CPicture*)AddControl(new CPicture(SWS_STATIC,L"",picInfo.m_rc, CMD_MSGBOX_PIC));
	ResCon.SetPicParam(pPic,picInfo);




	ResCon.GetBatTimePicParam(picInfo,L"LangIcon_Japanese");
	pPic = (CPicture*)AddControl(new CPicture(SWS_STATIC,L"",picInfo.m_rc, CMD_MSGBOX_PIC));
	ResCon.SetPicParam(pPic,picInfo);




	ResCon.GetBatTimePicParam(picInfo,L"LangIcon_Korea");
	pPic = (CPicture*)AddControl(new CPicture(SWS_STATIC,L"",picInfo.m_rc, CMD_MSGBOX_PIC));
	ResCon.SetPicParam(pPic,picInfo);


    ResCon.GetTabInfo(L"Btn_tab",m_vBtnRC);



	ResCon.GetTabInfo(L"Lan_tab",m_vLan);
	int i=0;
	ResCon.GetTextParam(txtInfo,L"CText_English");
	pText = (CText*)AddControl(new CText(SWS_STATICTEXT,m_vLan[i].m_strData.c_str(),txtInfo.m_rc, CMD_MSGBOX_TEXT));
	ResCon.SetTextParam(pText,txtInfo);
    i++;
	ResCon.GetTextParam(txtInfo,L"CText_German");
	pText = (CText*)AddControl(new CText(SWS_STATICTEXT,m_vLan[i].m_strData.c_str(),txtInfo.m_rc, CMD_MSGBOX_TEXT));
	ResCon.SetTextParam(pText,txtInfo);
    i++;

	ResCon.GetTextParam(txtInfo,L"CText_French");
	pText = (CText*)AddControl(new CText(SWS_STATICTEXT,m_vLan[i].m_strData.c_str(),txtInfo.m_rc, CMD_MSGBOX_TEXT));
	ResCon.SetTextParam(pText,txtInfo);
    i++;
	ResCon.GetTextParam(txtInfo,L"CText_Italian");
	pText = (CText*)AddControl(new CText(SWS_STATICTEXT,m_vLan[i].m_strData.c_str(),txtInfo.m_rc, CMD_MSGBOX_TEXT));
	ResCon.SetTextParam(pText,txtInfo);
    i++;

	ResCon.GetTextParam(txtInfo,L"CText_Spanish");
	pText = (CText*)AddControl(new CText(SWS_STATIC,m_vLan[i].m_strData.c_str(),txtInfo.m_rc, CMD_MSGBOX_TEXT));
	ResCon.SetTextParam(pText,txtInfo);
    i++;

	ResCon.GetTextParam(txtInfo,L"CText_Nederlands");
	pText = (CText*)AddControl(new CText(SWS_STATIC,m_vLan[i].m_strData.c_str(),txtInfo.m_rc, CMD_MSGBOX_TEXT));
	ResCon.SetTextParam(pText,txtInfo);
    i++;

	ResCon.GetTextParam(txtInfo,L"CText_Portuguess");
	pText = (CText*)AddControl(new CText(SWS_STATIC,m_vLan[i].m_strData.c_str(),txtInfo.m_rc, CMD_MSGBOX_TEXT));
	ResCon.SetTextParam(pText,txtInfo);
   i++;
	ResCon.GetTextParam(txtInfo,L"CText_ChineseGB");
	pText = (CText*)AddControl(new CText(SWS_STATIC,m_vLan[i].m_strData.c_str(),txtInfo.m_rc, CMD_MSGBOX_TEXT));
	ResCon.SetTextParam(pText,txtInfo);
    i++;

	ResCon.GetTextParam(txtInfo,L"CText_Japanese");
	pText = (CText*)AddControl(new CText(SWS_STATIC,m_vLan[i].m_strData.c_str(),txtInfo.m_rc, CMD_MSGBOX_TEXT));
	ResCon.SetTextParam(pText,txtInfo);
    i++;

	ResCon.GetTextParam(txtInfo,L"CText_Korea");
	pText = (CText*)AddControl(new CText(SWS_STATIC,m_vLan[i].m_strData.c_str(),txtInfo.m_rc, CMD_MSGBOX_TEXT));
	ResCon.SetTextParam(pText,txtInfo);
   i++;


    CCheckBtn* pCheckBtn=NULL;

	



	

	ResCon.GetBtnParam(btnInfo,L"CheckBtn_English");
	pCheckBtn = (CCheckBtn*)this->AddControl(new CCheckBtn(SBS_RECT, L"", btnInfo.m_rc, CMD_MSG_MSGLAN_CHECK_ENG));
	ResCon.SetBtnParam(pCheckBtn,btnInfo);
	if (m_strlang==L"EngLish.xml")
	{
		pCheckBtn->SetChecked(true);
	}
	else
	pCheckBtn->SetChecked(false);

	ResCon.GetBtnParam(btnInfo,L"CheckBtn_German");
	pCheckBtn = (CCheckBtn*)this->AddControl(new CCheckBtn(SBS_RECT, L"", btnInfo.m_rc, CMD_MSG_MSGLAN_CHECK_GRE));
	ResCon.SetBtnParam(pCheckBtn,btnInfo);
	if (m_strlang==L"German.xml")
	{
		pCheckBtn->SetChecked(true);
	}
	else
		pCheckBtn->SetChecked(false);

	ResCon.GetBtnParam(btnInfo,L"CheckBtn_French");
	pCheckBtn = (CCheckBtn*)this->AddControl(new CCheckBtn(SBS_RECT, L"", btnInfo.m_rc, CMD_MSG_MSGLAN_CHECK_FRE));
	ResCon.SetBtnParam(pCheckBtn,btnInfo);
	if (m_strlang==L"French.xml")
	{
		pCheckBtn->SetChecked(true);
	}
	else
		pCheckBtn->SetChecked(false);

	ResCon.GetBtnParam(btnInfo,L"CheckBtn_Italian");
	pCheckBtn = (CCheckBtn*)this->AddControl(new CCheckBtn(SBS_RECT, L"", btnInfo.m_rc, CMD_MSG_MSGLAN_CHECK_ITA));
	ResCon.SetBtnParam(pCheckBtn,btnInfo);
	if (m_strlang==L"Italian.xml")
	{
		pCheckBtn->SetChecked(true);
	}
	else
		pCheckBtn->SetChecked(false);

	ResCon.GetBtnParam(btnInfo,L"CheckBtn_Spanish");
	pCheckBtn = (CCheckBtn*)this->AddControl(new CCheckBtn(SBS_RECT, L"", btnInfo.m_rc, CMD_MSG_MSGLAN_CHECK_SPA));
	ResCon.SetBtnParam(pCheckBtn,btnInfo);
	if (m_strlang==L"Spanish.xml")
	{
		pCheckBtn->SetChecked(true);
	}
	else
		pCheckBtn->SetChecked(false);

	ResCon.GetBtnParam(btnInfo,L"CheckBtn_Nederlands");
	pCheckBtn = (CCheckBtn*)this->AddControl(new CCheckBtn(SBS_RECT, L"", btnInfo.m_rc, CMD_MSG_MSGLAN_CHECK_NED));
	ResCon.SetBtnParam(pCheckBtn,btnInfo);
	if (m_strlang==L"Nederlands.xml")
	{
		pCheckBtn->SetChecked(true);
	}
	else
		pCheckBtn->SetChecked(false);

	ResCon.GetBtnParam(btnInfo,L"CheckBtn_Portuguess");
	pCheckBtn = (CCheckBtn*)this->AddControl(new CCheckBtn(SBS_RECT, L"", btnInfo.m_rc, CMD_MSG_MSGLAN_CHECK_POR));
	ResCon.SetBtnParam(pCheckBtn,btnInfo);
	if (m_strlang==L"Portuguess.xml")
	{
		pCheckBtn->SetChecked(true);
	}
	else
		pCheckBtn->SetChecked(false);

	ResCon.GetBtnParam(btnInfo,L"CheckBtn_ChineseGB");
	pCheckBtn = (CCheckBtn*)this->AddControl(new CCheckBtn(SBS_RECT, L"", btnInfo.m_rc, CMD_MSG_MSGLAN_CHECK_CHINA));
	ResCon.SetBtnParam(pCheckBtn,btnInfo);
	if (m_strlang==L"ChineseGB.xml")
	{
		pCheckBtn->SetChecked(true);
	}
	else
		pCheckBtn->SetChecked(false);

	ResCon.GetBtnParam(btnInfo,L"CheckBtn_Japanese");
	pCheckBtn = (CCheckBtn*)this->AddControl(new CCheckBtn(SBS_RECT, L"", btnInfo.m_rc, CMD_MSG_MSGLAN_CHECK_JAP));
	ResCon.SetBtnParam(pCheckBtn,btnInfo);
	if (m_strlang==L"Japanese.xml")
	{
		pCheckBtn->SetChecked(true);
	}
	else
		pCheckBtn->SetChecked(false);


	ResCon.GetBtnParam(btnInfo,L"CheckBtn_Korea");
	pCheckBtn = (CCheckBtn*)this->AddControl(new CCheckBtn(SBS_RECT, L"", btnInfo.m_rc, CMD_MSG_MSGLAN_CHECK_KOREA));
	ResCon.SetBtnParam(pCheckBtn,btnInfo);
	if (m_strlang==L"Korea.xml")
	{
		pCheckBtn->SetChecked(true);
	}
	else
		pCheckBtn->SetChecked(false);








	SetPainter(new CMainMenuPainter());
	return true;
}

void  CMSGLanguageCon::SaveLangaue(BOOL bFlag)
{
   LANGUAGE_DECLARE;
	if (bFlag)
    {
		m_strlang=m_setstrLang;
		CConfig::GetInstance()->SetLanguage(m_setstrLang.c_str());
		pLang->SetLanguageFile(m_setstrLang.c_str());

		CUtil::BroadcastMessage(BC_ALL,WM_LAN_CHANGE,0,0);
    }
	else
	{
        pLang->SetLanguageFile(m_strlang.c_str());
		CConfig::GetInstance()->SetLanguage(m_strlang.c_str());
	}


}
 void   CMSGLanguageCon::OnLButtonUp(UINT nFlags, CPoint point)
{

  for (int i=0;i<m_vBtnRC.size();i++)
  {
	   CRect rc;
	   CIResCfg ResCon;
	   rc=ResCon.GetRectFromString(m_vBtnRC[i].m_strPara);
	  if (PtInRect(rc,point))
	  {
		  PostMessage(m_hWnd,WM_COMMAND, CMD_MSG_MSGLAN_CHECK_ENG+i,NULL);
		  return ;
	  }
  }
  CMSGInforCon::OnLButtonUp(nFlags,  point);
}
void  CMSGLanguageCon::OnCommand(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
   CCheckBtn *pBtn=NULL;
	switch(wParam)
	{
	case CMD_MSG_MSGLAN_CHECK_ENG:
		for(int i=CMD_MSG_MSGLAN_CHECK_ENG;i<CMD_MSG_MSGLAN_CHECK_ENG+10;i++)
		{
            pBtn=  (CCheckBtn *)ControlFromID(i);
			if (i==CMD_MSG_MSGLAN_CHECK_ENG)
			{
				pBtn->SetChecked(true);

				//CConfig::GetInstance()->SetLanguage(L"EngLish.xml");
				m_setstrLang=L"English.xml";
				continue;
			}
			 	pBtn->SetChecked(false);
		}
		break;
	case CMD_MSG_MSGLAN_CHECK_ENG+1:
		for(int i=CMD_MSG_MSGLAN_CHECK_ENG;i<CMD_MSG_MSGLAN_CHECK_ENG+10;i++)
		{
			pBtn=  (CCheckBtn *)ControlFromID(i);
			if (i==CMD_MSG_MSGLAN_CHECK_ENG+1)
			{
				pBtn->SetChecked(true);
				//CConfig::GetInstance()->SetLanguage(L"German.xml");
			   
		       m_setstrLang=L"German.xml";

				continue;
			}
			pBtn->SetChecked(false);
		}
		break;
	case CMD_MSG_MSGLAN_CHECK_ENG+2:
		for(int i=CMD_MSG_MSGLAN_CHECK_ENG;i<CMD_MSG_MSGLAN_CHECK_ENG+10;i++)
		{
			pBtn=  (CCheckBtn *)ControlFromID(i);
			if (i==CMD_MSG_MSGLAN_CHECK_ENG+2)
			{
				pBtn->SetChecked(true);
			//	CConfig::GetInstance()->SetLanguage(L"France.xml");
				m_setstrLang=L"French.xml";

			

				continue;
			}
			pBtn->SetChecked(false);
		}
		break;
	case CMD_MSG_MSGLAN_CHECK_ENG+3:
		for(int i=CMD_MSG_MSGLAN_CHECK_ENG;i<CMD_MSG_MSGLAN_CHECK_ENG+10;i++)
		{
			pBtn=  (CCheckBtn *)ControlFromID(i);
			if (i==CMD_MSG_MSGLAN_CHECK_ENG+3)
			{
				pBtn->SetChecked(true);
			
				//CConfig::GetInstance()->SetLanguage(L"Italian.xml");
				m_setstrLang=L"Italian.xml";
				continue;
			}
			pBtn->SetChecked(false);
		}
		break;
	case CMD_MSG_MSGLAN_CHECK_ENG+4:
		for(int i=CMD_MSG_MSGLAN_CHECK_ENG;i<CMD_MSG_MSGLAN_CHECK_ENG+10;i++)
		{
			pBtn=  (CCheckBtn *)ControlFromID(i);
			if (i==CMD_MSG_MSGLAN_CHECK_ENG+4)
			{
				pBtn->SetChecked(true);
				
				//CConfig::GetInstance()->SetLanguage(L"Spanish.xml");
				m_setstrLang=L"Spanish.xml";

				continue;
			}
			pBtn->SetChecked(false);
		}
		break;
	case CMD_MSG_MSGLAN_CHECK_ENG+5:
		for(int i=CMD_MSG_MSGLAN_CHECK_ENG;i<CMD_MSG_MSGLAN_CHECK_ENG+10;i++)
		{
			pBtn=  (CCheckBtn *)ControlFromID(i);
			if (i==CMD_MSG_MSGLAN_CHECK_ENG+5)
			{
				pBtn->SetChecked(true);

				//CConfig::GetInstance()->SetLanguage(L"Nederlands.xml");
				m_setstrLang=L"Nederlands.xml";

				continue;
			}
			pBtn->SetChecked(false);
		}
		break;
	case CMD_MSG_MSGLAN_CHECK_ENG+6:
		for(int i=CMD_MSG_MSGLAN_CHECK_ENG;i<CMD_MSG_MSGLAN_CHECK_ENG+10;i++)
		{
			pBtn=  (CCheckBtn *)ControlFromID(i);
			if (i==CMD_MSG_MSGLAN_CHECK_ENG+6)
			{
				pBtn->SetChecked(true);

		
				//CConfig::GetInstance()->SetLanguage(L"Portuguess.xml");
				m_setstrLang=L"Portuguess.xml";

				continue;
			}
			pBtn->SetChecked(false);
		}
		break;
	case CMD_MSG_MSGLAN_CHECK_ENG+7:
		for(int i=CMD_MSG_MSGLAN_CHECK_ENG;i<CMD_MSG_MSGLAN_CHECK_ENG+10;i++)
		{
			pBtn=  (CCheckBtn *)ControlFromID(i);
			if (i==CMD_MSG_MSGLAN_CHECK_ENG+7)
			{
				pBtn->SetChecked(true);
			
				//CConfig::GetInstance()->SetLanguage(L"ChineseGB.xml");
				m_setstrLang=L"ChineseGB.xml";
				
				continue;
			}
			pBtn->SetChecked(false);
		}
		break;
	case CMD_MSG_MSGLAN_CHECK_ENG+8:
		for(int i=CMD_MSG_MSGLAN_CHECK_ENG;i<CMD_MSG_MSGLAN_CHECK_ENG+10;i++)
		{
			pBtn=  (CCheckBtn *)ControlFromID(i);
			if (i==CMD_MSG_MSGLAN_CHECK_ENG+8)
			{
				pBtn->SetChecked(true);

				//CConfig::GetInstance()->SetLanguage(L"Japanese.xml");

                m_setstrLang=L"Japanese.xml";
				continue;
			}
			pBtn->SetChecked(false);
		}
		break;
	case CMD_MSG_MSGLAN_CHECK_ENG+9:
		for(int i=CMD_MSG_MSGLAN_CHECK_ENG;i<CMD_MSG_MSGLAN_CHECK_ENG+10;i++)
		{
			pBtn=  (CCheckBtn *)ControlFromID(i);
			if (i==CMD_MSG_MSGLAN_CHECK_ENG+9)
			{
				pBtn->SetChecked(true);
				//CConfig::GetInstance()->SetLanguage(L"Korea.xml");
				 m_setstrLang=L"Korea.xml";
				continue;
			}
			pBtn->SetChecked(false);
		}
		break;
	

	}
	InvalidateRect(m_hWnd,NULL,FALSE);

}